package com.lvmama.java.rhino.spark.utils;

import java.io.IOException;
import java.util.Properties;

public final class Constants {

	private static Properties properties;
	private static volatile Constants instance = null;
	public static final String DOMAIN = "10.112.5.11";
	/** 日志系统回话ID */
	public static final String LOGSESSIONID = "logsessionid";
	/** 日志系统回话中的用户信息key */
	public static final String SESSION_USER_KEY = "user";
	/** 日志系统回话超时时间（分钟） */
	public static final int SESSION_TIMEOUT = 30;
	/** Session最后一次更新时间 */
	public static final String SESSION_LAST_UPDATE_TIME = "last_update_time";
	/** Spark程序运行状态在Zookeeper中存储的根目录 */
	public static final String SPARK_ZOOKEEPER_ROOT = "/lvtu_spark";
	/** 整个线程日志结束标志 */
	public static final String LOG_END_FLAG = "FLUME-LOG-END";
	/** 请求公共参数分隔符 */
	public static final String SEPERATOR = "\001";
	/** 请求公共参数打印标识 */
	public static final String COMMON_PARAM_DATA = "FlumeClientServiceCommonParamFlag.java";
	/** 请求特殊参数打印标识 */
	public static final String SPECIAL_PARAM_DATA = "FlumeClientServiceSpecialParamFlag.java";
	/** DUBBO打印性能日志 */
	public static final String DUBBO_PARAM_DATA = "DubboInvoker.java";
	/** 日志搜索elastic索引名称 */
	public static final String ELASTIC_INDEX_LVTU_INDEX = "lvtu_log_index";
	/** 日志搜索-日志基本信息-elastic索引类型 */
	public static final String ELASTIC_TYPE_BASE_PARAM_TYPE = "log_base_param";
	/** 日志搜索-日志详细信息-elastic索引类型 */
	public static final String ELASTIC_TYPE_LOG_DETAIL_TYPE = "log_detail";
	
	private Constants() {
		init();
	}

	private void init() {
		try {
			properties = new Properties();
			properties.load(getClass().getResourceAsStream("/rhino.const.properties"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static Constants getInstance() {
		if (instance == null) {
			synchronized (Constants.class) {
				if (instance == null) {
					instance = new Constants();
				}
			}
		}
		return instance;
	}

	public String getProperty(String key) {
		return getValue(key);
	}

	public String getValue(String key) {
		return System.getProperty(key) != null ? System.getProperty(key) : properties.getProperty(key);
	}
	
	public static enum CODE {
		OK("1", "成功"),
		ERROR("-1", "失败");
		private String code;
		private String cnName;
		private CODE(String code, String cnName) {
			this.code = code;
			this.cnName = cnName;
		}
		public String getCode() {
			return code;
		}
		public void setCode(String code) {
			this.code = code;
		}
		public String getCnName() {
			return cnName;
		}
		public void setCnName(String cnName) {
			this.cnName = cnName;
		}
	}
	
	public static enum SHELL_STATUS {
		RUNNING("0", "正在运行"),ERROR("-1", "执行失败"),SUCCESS("1", "执行成功");
		private String code;
		private String info;
		private SHELL_STATUS(String code, String info) {
			this.setCode(code);
			this.info = info;
		}
		public String getInfo() {
			return info;
		}
		public void setInfo(String info) {
			this.info = info;
		}
		public String getCode() {
			return code;
		}
		public void setCode(String code) {
			this.code = code;
		}
	}
}
